import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
// #ifdef WEB
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite'
import NutUIResolver from '@nutui/auto-import-resolver'
import { VantResolver } from '@vant/auto-import-resolver';
// #endif

// https://vitejs.dev/config/
/** @type {import('vite').UserConfig} */
export default defineConfig({
  plugins: [
    uni(),
    // #ifdef WEB
    AutoImport({
      resolvers: [
        VantResolver()
      ],
    }),
    // #endif
    // #ifdef WEB
    Components({
      resolvers: [
        NutUIResolver(),
        VantResolver(),
      ],
    }),
    // #endif
  ],
  css: {
    preprocessorOptions: {
      scss: {
        // #ifdef WEB
        // 默认主题 京东APP10.0主题
        additionalData: `@use "@nutui/nutui/dist/styles/variables.scss";`,
        // 京东科技主题
        // additionalData: `@use "@nutui/nutui/dist/styles/variables-jdt.scss";`,
        // 京东B商城主题
        // additionalData: `@use "@nutui/nutui/dist/styles/variables-jdb.scss";`,
        // 京东企业业务主题
        // additionalData: `@use "@nutui/nutui/dist/styles/variables-jddkh.scss";`,
        // #endif
        quietDeps: true,
        silenceDeprecations: ['legacy-js-api'],
      }
    }
  },
  server: {
    host: '0.0.0.0',
    port: 5173,
    open: false,
    proxy: {
      // H5 开发跨域问题
      '/dev-api': {
        target: 'http://127.0.0.1:8000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/dev-api/, '')
      }
    },
  },
  build: {
    assetsDir: 'static',
    rollupOptions: {
      output: {
        chunkFileNames: 'static/js/[name]-[hash].js',
        entryFileNames: 'static/js/[name]-[hash].js',
        assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
      }
    },
    minify: 'terser',
    terserOptions: {
      compress: {
        // drop_console: true,
      },
    },
  }
})
